package com.wms.web.action;

import com.wms.model.Menu;
import com.wms.service.MenuService;
import org.springframework.beans.factory.annotation.Autowired;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author This
 * @version 1.0
 * @date 2019/7/14 12:50
 */
public class MenuAction extends BaseAction<Menu> {
    @Autowired
    private MenuService service;

    public void hasMenu() {
        if (service.count(null) < 1) {
            List<Menu> menus = new ArrayList<Menu>();
            Menu menu1 = new Menu(null, "产品管理", "product", null, "#", 0, (byte) 1, (byte) 1);
            menus.add(menu1);
            Menu menu2 = new Menu(null, "产品列表", "product_list", null, "page_product", 1, (byte) 0, (byte) 1);
            menus.add(menu2);
            Menu menu3 = new Menu(null, "产品颜色", "product_color", null, "page_color", 1, (byte) 1, (byte) 1);
            menus.add(menu3);
            Menu menu4 = new Menu(null, "产品尺寸", "product_size", null, "page_size", 1, (byte) 1, (byte) 1);
            menus.add(menu4);
            Menu menu5 = new Menu(null, "客户管理", "customer", null, "#", 0, (byte) 1, (byte) 1);
            menus.add(menu5);
            Menu menu6 = new Menu(null, "客户列表", "customer_list", null, "page_customer", 5, (byte) 0, (byte) 1);
            menus.add(menu6);
            Menu menu7 = new Menu(null, "订单管理", "order", null, "#", 0, (byte) 1, (byte) 1);
            menus.add(menu7);
            Menu menu8 = new Menu(null, "订单列表", "order_list", null, "page_order", 7, (byte) 0, (byte) 1);
            menus.add(menu8);
            Menu menu9 = new Menu(null, "仓库管理", "storage", null, "#", 0, (byte) 1, (byte) 1);
            menus.add(menu9);
            Menu menu10 = new Menu(null, "库存管理", "storage_list", null, "page_storage", 9, (byte) 0, (byte) 1);
            menus.add(menu10);
            Menu menu11 = new Menu(null, "入库管理", "in_storage", null, "page_in_storage", 9, (byte) 1, (byte) 1);
            menus.add(menu11);
            Menu menu12 = new Menu(null, "出库管理", "out_storage", null, "page_out_storage", 9, (byte) 1, (byte) 1);
            menus.add(menu12);
            service.addAll(menus);
        }
    }

    @Override
    public void save() {

    }

    @Override
    public void edit() {

    }

    @Override
    public void delete() throws IOException {

    }

    @Override
    public void showList() {

    }

    public void getAll() throws IOException {
        List<Menu> menus = service.findAll();
        Map<String, List<Menu>> menuMap = new HashMap<String, List<Menu>>();
        List<Menu> topMenu = new ArrayList<Menu>();
        List<Menu> leftMenu = new ArrayList<Menu>();
        for (Menu menu : menus) {
            if (menu.getType() == 0 || menu.getType() == 2) {
                leftMenu.add(menu);
            }

            if (menu.getType() == 0 || menu.getType() == 1) {
                topMenu.add(menu);
            }
        }
        menuMap.put("top_menu", topMenu);
        menuMap.put("left_menu", leftMenu);
        responseJson(menuMap, new String[]{});
    }
}
